package com.baiyun.test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyJFrame2 extends JFrame implements MouseListener {
    JButton jtb1 = new JButton("点我啊");
    JButton jtb2 = new JButton("你敢点我吗");

    public MyJFrame2() {
        this.setLayout(null);
        //设置长宽高
        this.setSize(603, 680);
        //设置标题
        this.setTitle("拼图单机版 v1.0");
        //将界面置顶
        this.setAlwaysOnTop(true);
        //界面居中
        this.setLocationRelativeTo(null);

        //创建一个按钮
        jtb1.setBounds(0, 0, 100, 50);
        jtb1.addMouseListener(this);

        jtb2.setBounds(100, 0, 100, 50);
        jtb2.addMouseListener(this);

        this.getContentPane().add(jtb1);
        this.getContentPane().add(jtb2);
        //点X后让界面消失
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //保证界面不消失
        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("点击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按住不松");

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开键盘");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("移入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("移出");
    }
}
